<template>
  <el-dialog title="扫码支付设置" :visible.sync="dialogFormVisible" @closed="closed">
    <el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px">
      <el-form-item label="商户号" prop="merchantNo">
        <el-input v-model="form.merchantNo"/>
      </el-form-item>
      <el-form-item label="终端号" prop="terminalId">
        <el-input v-model="form.terminalId"/>
      </el-form-item>
      <el-form-item label="令牌" prop="accessToken">
        <el-input v-model="form.accessToken"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="submitForm" :disabled="disabled">确 定</el-button>
    </div>
  </el-dialog>

</template>

<script>
import { addOrUpdateScanPaySetting, getPayConfig } from '@/api/payment/payConfig'

export default {
  name: 'PayMethodScanPaySetting',
  components: {},
  props: {},
  data() {
    //这里存放数据
    return {
      dialogFormVisible: false,
      disabled: false,
      form: {
        accessToken: '',
        id: 0,
        merchantNo: '',
        sellerId: 0,
        terminalId: ''
      },
      rules: {
        merchantNo: [
          { required: true, message: '请输入商户号', trigger: 'blur' }
        ],
        terminalId: [
          { required: true, message: '请输入终端号', trigger: 'blur' }
        ],
        accessToken: [{ required: true, message: '请输入令牌', trigger: 'blur' }]
      }
    }
  },
  methods: {
    /**
     * 提交数据
     *
     */
    submitForm() {
      this.disabled = true
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          addOrUpdateScanPaySetting(this.form).then((response) => {
            this.$modal.msgSuccess(response.msg)
            this.closed()
          })
        } else {
          this.disabled = false
        }
      })
    },
    /**
     * 获取信息
     */
    getInfo() {
      getPayConfig()
        .then(response => {
          this.form = response.data
        })
    },
    /**
     * 初始化
     */
    init() {
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.getInfo()
      })
    },
    /**
     * 关闭
     */
    closed() {
      this.dialogFormVisible = false
      this.$emit('closed')
    }
  }
}
</script>
<style scoped>

</style>
